pp108 : Using a Business Rule in an XForm

Using a Business Rule in an XForm

This topic describes the use of a business rule in an XForm.

Before you begin this task:
Ensure that the Cordys XForms Runtime, and Cordys WS-AppServer application packages are installed.

Process Platform supports the use of business rules to help define a business process. In a business workflow comprising multiple business processes, the business rules set for each process facilitate intra and inter enterprise collaboration. In a workflow implementation, the business rules determine how various business functions are structured towards the completion of the workflow.

Business rules apply on Business Objects and comprise the logic according to which a business object must function in a given situation. Using Cordys WS-AppServer, you can apply business rules to the business objects in an application created using Process Platform XForms. The integration of XForms with WS-AppServer enables the execution of these rules in an XForm.

For example, consider a business scenario in which it is required that an order placed by a customer must not exceed 100 units. In this case, a rule needs to be defined to reject additional units, after 100 units are already selected for an order. Additionally, a notification needs to be sent to the customer specifying these order details. For information about business rules applicable in Process Platform, see Rules.

For this example we use the Orders and Order Details tables of the Northwind database (MS-SQL Server). The following figure depicts the schematic representation of the tables and their relationship.

  1. Configure the WS-AppServer service container to point to the appropriate database (in this case, the Northwind database). See WS-AppServer service container configuration, for details. Also, ensure that the related packages, Java Classes, and Web service interfaces exist or are created for the Orders and Order Details table. These classes contain basic implementation for the generated Web service interfaces. For details, see Extending the Business Logic using Custom Classes.
  2. Enable WS-AppServer integration with XForms by selecting the WS-AppServer Integration check box in the Model Properties dialog box.
  3. Use the Rule Editor to create a rule.
    1. Select the package for which to create the rule from the WS-AppServer Package window (navigate to Workspace Documents (Explorer) > <solution> > <project> and click ), and provide appropriate details.
    2. Right-click a model and select Create Rule. The Rule Editor appears.
    3. In the Properties tab, enter the appropriate details. For information about the options available in the Properties tab, see properties of a rule.
    4. In the Behavior tab, click in the Rule Definition pane to define the condition. The Set Condition pane appears.
    5. From the Business Objects pane, drag the Quantity attribute of the OrderDetails object to the Set Condition pane and build the required expression using the functions in Function Library. Click Add. The specified condition is displayed next to in the Rule Definition pane.
    6. Right-click then in the Rule Definition pane, select Send Notification, specify appropriate details for the notification message in the Action - Send Notification pane that appears, and click Add. The defined action is displayed next to in the Rule Definition pane.
    7. Right-click then in the Rule Definition pane, select Abort Transaction, specify appropriate details for the notification message in the Action - Abort Order pane that appears and click Add. The defined action is displayed next to in the Rule Definition pane.
    8. Click to save the rule.
  4. Create the XForm using the base Web service operation and associate controls to the appropriate Web service operations.
    In this case, drag the GetOrdersObjects and GetOrderDetailsObjectsByOrderID Web service operations from the Insert tab to create the XForm, and associate them to get the right data. For information about associating Web service operations, see Adding and Associating Multiple Models.

    By default, a SOAP fault is displayed when you enter data for a new order, or change an existing order quantity to more than 100. Use the following code to display a custom message instead:

    if (eventObject.faultString.indexOf("Order can not exceed 100 units") > 0) { application.showError("Order aborted. Order units can not exceed 100. See mail in your Inbox for more details."); eventObject.showError = false; OrderDetailsModel.undo(); }



    This enables the use of the business logic in the XForm.

Related tasks

Invoking a Web service in Rules
Triggering a Business Process from Rules
Triggering Rules from a Business Process Model
Using WS-AppServer Business Logic in XForms